package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import com.example.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.ext.entity.maintenance.ExtDebrisDto;
import com.example.ext.entity.maintenance.ExtDebrisHalfMon;
import com.example.ext.entity.maintenance.ExtEscalatorDto;
import com.example.ext.entity.maintenance.ExtEscalatorHalfMon;
import com.example.ext.entity.maintenance.ExtHydpressDto;
import com.example.ext.entity.maintenance.ExtHydpressHalfMon;
import com.example.ext.entity.maintenance.ExtTractionDto;
import com.example.ext.entity.maintenance.ExtTractionHalfMon;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * Created by douyx on 2017/10/26.
 */
@RestController
public class EevatorMaintController {

	@Autowired
	private DebrisService debrisService;

	@Autowired
	private EscalatorService escalatorService;

	@Autowired
	private HydpressService hydpressService;

	@Autowired
	private TractionService tractionService;

	@Autowired
	private ElevatorService elevatorService;

	@ApiOperation(value = "新增杂物电梯维保数据", notes = "新增杂物电梯维保数据")
	@ApiImplicitParam(name = "debris", value = "杂物电梯维保数据", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/addDebris", method = RequestMethod.POST)
	Map<String, Object> addDebris(@RequestBody ExtDebrisDto debris) {
		Map<String, Object> res = debrisService.addDebris(debris);
		if("200".equals(res.get("status")+"")){
			Map<String, Object> inMap = new HashMap();
			inMap.put("elevatorNum",debris.getDebrisHalfMon().getElevatorNum());
			if("1".equals(debris.getDebrisHalfMon().getType())){
				elevatorService.updatehmMaintDate(inMap);
			}
			if("2".equals(debris.getDebrisHalfMon().getType())){
				elevatorService.updateqMaintDate(inMap);
			}
			if("3".equals(debris.getDebrisHalfMon().getType())){
				elevatorService.updatehyMaintDate(inMap);
			}
			if("4".equals(debris.getDebrisHalfMon().getType())){
				elevatorService.updateyMaintDate(inMap);
			}

		}
		return res;
	}

	@ApiOperation(value = "获取杂物电梯维保数据", notes = "获取杂物电梯维保数据")
	@ApiImplicitParam(name = "debris", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryDebris", method = RequestMethod.POST)
	Map<String, Object> queryDebris(@RequestBody ExtDebrisHalfMon debris) {
		return debrisService.queryDebris(debris);
	}

	@ApiOperation(value = "获取杂物电梯维保明细数据", notes = "获取杂物电梯维保明细数据")
	@ApiImplicitParam(name = "id", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryDebrisDetails/{id}", method = RequestMethod.POST)
	Map<String, Object> queryDebris(@PathVariable Long id) {
		return debrisService.queryDebrisDetails(id);
	}

	@ApiOperation(value = "新增自动扶梯 人行道维保数据", notes = "新增自动扶梯 人行道维保数据")
	@ApiImplicitParam(name = "escalator", value = "自动扶梯 人行道维保数据", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/addEscalator", method = RequestMethod.POST)
	Map<String, Object> addEscalator(@RequestBody ExtEscalatorDto escalator) {
		Map<String, Object> res = escalatorService.addEscalator(escalator);
		if("200".equals(res.get("status")+"")){
			Map<String, Object> inMap = new HashMap();
			inMap.put("elevatorNum",escalator.getEscalatorHalfMon().getElevatorNum());
			if("1".equals(escalator.getEscalatorHalfMon().getType())){
				elevatorService.updatehmMaintDate(inMap);
			}
			if("2".equals(escalator.getEscalatorHalfMon().getType())){
				elevatorService.updateqMaintDate(inMap);
			}
			if("3".equals(escalator.getEscalatorHalfMon().getType())){
				elevatorService.updatehyMaintDate(inMap);
			}
			if("4".equals(escalator.getEscalatorHalfMon().getType())){
				elevatorService.updateyMaintDate(inMap);
			}

		}
		return res;
	}

	@ApiOperation(value = "获取自动扶梯 人行道维保数据", notes = "获取自动扶梯 人行道维保数据")
	@ApiImplicitParam(name = "escalator", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryEscalator", method = RequestMethod.POST)
	Map<String, Object> queryEscalator(@RequestBody ExtEscalatorHalfMon escalator) {
		return escalatorService.queryEscalator(escalator);
	}

	@ApiOperation(value = "获取自动扶梯 人行道维保明细数据", notes = "获取自动扶梯 人行道维保明细数据")
	@ApiImplicitParam(name = "id", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryEscalatorDetails/{id}", method = RequestMethod.POST)
	Map<String, Object> queryEscalator(@PathVariable Long id) {
		return escalatorService.queryEscalatorDetails(id);
	}

	@ApiOperation(value = "新增液压电梯维保数据", notes = "新增液压电梯维保数据")
	@ApiImplicitParam(name = "hydpress", value = "液压电梯维保数据", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/addHydpress", method = RequestMethod.POST)
	Map<String, Object> addHydpress(@RequestBody ExtHydpressDto hydpress) {
		Map<String, Object> res = hydpressService.addHydpress(hydpress);
		if("200".equals(res.get("status")+"")){
			Map<String, Object> inMap = new HashMap();
			inMap.put("elevatorNum",hydpress.getHydpressHalfMon().getElevatorNum());
			if("1".equals(hydpress.getHydpressHalfMon().getType())){
				elevatorService.updatehmMaintDate(inMap);
			}
			if("2".equals(hydpress.getHydpressHalfMon().getType())){
				elevatorService.updateqMaintDate(inMap);
			}
			if("3".equals(hydpress.getHydpressHalfMon().getType())){
				elevatorService.updatehyMaintDate(inMap);
			}
			if("4".equals(hydpress.getHydpressHalfMon().getType())){
				elevatorService.updateyMaintDate(inMap);
			}

		}
		return res;
	}
	
	@ApiOperation(value = "获取液压电梯维保数据", notes = "获取液压电梯维保数据")
	@ApiImplicitParam(name = "hydpress", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryHydpress", method = RequestMethod.POST)
	Map<String, Object> queryHydpress(@RequestBody ExtHydpressHalfMon hydpress) {
		return hydpressService.queryHydpress(hydpress);
	}

	@ApiOperation(value = "获取液压电梯维保明细数据", notes = "获取液压电梯维保明细数据")
	@ApiImplicitParam(name = "id", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryHydpressDetails/{id}", method = RequestMethod.POST)
	Map<String, Object> queryHydpressDetails(@PathVariable String id) {
		return hydpressService.queryHydpressDetails(id);
	}

	@ApiOperation(value = "新增曳引电梯维保数据", notes = "新增曳引电梯维保数据")
	@ApiImplicitParam(name = "traction", value = "曳引电梯维保数据", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/addTraction", method = RequestMethod.POST)
	Map<String, Object> addTraction(@RequestBody ExtTractionDto traction) {
		Map<String, Object> res = tractionService.addTraction(traction);
		if("200".equals(res.get("status")+"")){
			Map<String, Object> inMap = new HashMap();
			inMap.put("elevatorNum",traction.getTractionHalfMon().getElevatorNum());
			if("1".equals(traction.getTractionHalfMon().getType())){
				elevatorService.updatehmMaintDate(inMap);
			}
			if("2".equals(traction.getTractionHalfMon().getType())){
				elevatorService.updateqMaintDate(inMap);
			}
			if("3".equals(traction.getTractionHalfMon().getType())){
				elevatorService.updatehyMaintDate(inMap);
			}
			if("4".equals(traction.getTractionHalfMon().getType())){
				elevatorService.updateyMaintDate(inMap);
			}

		}
		return res;
	}
	
	@ApiOperation(value = "获取曳引电梯维保数据", notes = "获取曳引电梯维保数据")
	@ApiImplicitParam(name = "traction", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryTraction", method = RequestMethod.POST)
	Map<String, Object> queryTraction(@RequestBody ExtTractionHalfMon traction) {
		return tractionService.queryTraction(traction);
	}

	@ApiOperation(value = "获取曳引电梯维保明细数据", notes = "获取曳引电梯维保明细数据")
	@ApiImplicitParam(name = "id", value = "查询条件", dataType = "String", required = true)
	@RequestMapping(value = "api/maint/queryTractionDetails/{id}", method = RequestMethod.POST)
	Map<String, Object> queryTraction(@PathVariable Long id) {
		return tractionService.queryTractionDetails(id);
	}
}
